class Solution {
public:
    void dfs(Node*node,vector<int>& arr){
        if(!node){return ;}
        arr.push_back(node->val);
        for(int i=0;i<node->children.size();i++){
            if(node->children[i]){
                dfs(node->children[i],arr);
            }
        }
    }
    vector<int> preorder(Node* root) {
        vector<int>arr;
        dfs(root,arr);
        return arr;
    }
};